﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DiveManager
{
    public partial class ModulKeyAdd : Form
    {
        public Guid modulkey;
        public DateTime date =System.DateTime.Now;

        public bool einstellungen = false;
        public bool verkauf = false;
        public bool warenwirtschaft = false;
        public bool verleih = false;
        public bool staffbereich = false;
        public bool aktivitäten = false;
        public bool reports = false;
        public bool kursverwaltung = false;
        public bool finanzen = false;
        public bool kunden = false;
        public bool einkleidung = false;

        public String status="frei";

        protected DiveDatabaseEntities diveDatabase;
        
        public ModulKeyAdd()
        {
            InitializeComponent();

            //init Dtatbase
            diveDatabase = new DiveDatabaseEntities();
        }

        private void btNewKey_Click(object sender, EventArgs e)
        {
            //Neuen Schlüssel erstellen
            modulkey = System.Guid.NewGuid();
            txShowKey.Text = modulkey.ToString();

            groupBox2.Enabled = true;
            groupBox3.Enabled = true;
        }

        private void btEinstellungenFrei_Click(object sender, EventArgs e)
        {
            einstellungen = true;
            btEinstellungenFrei.Visible = false;
            btEinstellungenClose.Visible = true;
            lbEinstellungen.BackColor = System.Drawing.Color.Green;
        }

        private void btVerkaufFrei_Click(object sender, EventArgs e)
        {
            verkauf = true;
            btVerkaufFrei.Visible = false;
            btVerkaufClose.Visible = true;
            lbVerkauf.BackColor = System.Drawing.Color.Green;
        }

        private void btWarenwirtschaftFrei_Click(object sender, EventArgs e)
        {
            warenwirtschaft = true;
            btWarenwirtschaftFrei.Visible = false;
            btWarenwirtschaftClose.Visible = true;
            lbWarenwirtschaft.BackColor = System.Drawing.Color.Green;
        }

        private void btVerleihFrei_Click(object sender, EventArgs e)
        {
            verleih = true;
            btVerleihFrei.Visible = false;
            btVerleihClose.Visible = true;
            lbVerleih.BackColor = System.Drawing.Color.Green;
        }

        private void btStaffbereichFrei_Click(object sender, EventArgs e)
        {
            staffbereich = true;
            btStaffbereichFrei.Visible = false;
            btStaffbereichClose.Visible = true;
            lbStaffbereich.BackColor = System.Drawing.Color.Green;
        }

        private void btAktivitätenFrei_Click(object sender, EventArgs e)
        {
            aktivitäten = true;
            btAktivitätenFrei.Visible = false;
            btAktivitätenClose.Visible = true;
            lbAktivitäten.BackColor = System.Drawing.Color.Green;
        }

        private void btReportsFrei_Click(object sender, EventArgs e)
        {
            reports = true;
            btReportsFrei.Visible = false;
            btReportsClose.Visible = true;
            lbReports.BackColor = System.Drawing.Color.Green;
        }

        private void btKursverwaltungFrei_Click(object sender, EventArgs e)
        {
            kursverwaltung = true;
            btKursverwaltungFrei.Visible = false;
            btKursverwaltungClose.Visible = true;
            lbKursverwaltung.BackColor = System.Drawing.Color.Green;
        }

        private void btFinanzenFrei_Click(object sender, EventArgs e)
        {
            finanzen = true;
            btFinanzenFrei.Visible = false;
            btFinanzenClose.Visible = true;
            lbFinanzen.BackColor = System.Drawing.Color.Green;
        }

        private void btKundenFrei_Click(object sender, EventArgs e)
        {
            kunden = true;
            btKundenFrei.Visible = false;
            btKundenClose.Visible = true;
            lbKunden.BackColor = System.Drawing.Color.Green;
        }

        private void btEinkleidungFrei_Click(object sender, EventArgs e)
        {
            einkleidung = true;
            btEinkleidungFrei.Visible = false;
            btEinkleidungClose.Visible = true;
            lbEinkleidung.BackColor = System.Drawing.Color.Green;
        }

        private void btEinstellungenClose_Click(object sender, EventArgs e)
        {
            einstellungen = false;
            btEinstellungenFrei.Visible = true;
            btEinstellungenClose.Visible = false;
            lbEinstellungen.BackColor = System.Drawing.Color.Red;
        }

        private void btVerkaufClose_Click(object sender, EventArgs e)
        {
            verkauf = false;
            btVerkaufFrei.Visible = true;
            btVerkaufClose.Visible = false;
            lbVerkauf.BackColor = System.Drawing.Color.Red;
        }

        private void btWarenwirtschaftClose_Click(object sender, EventArgs e)
        {
            warenwirtschaft = false;
            btWarenwirtschaftFrei.Visible = true;
            btWarenwirtschaftClose.Visible = false;
            lbWarenwirtschaft.BackColor = System.Drawing.Color.Red;
        }

        private void btVerleihClose_Click(object sender, EventArgs e)
        {
            verleih = false;
            btVerleihFrei.Visible = true;
            btVerleihClose.Visible = false;
            lbVerleih.BackColor = System.Drawing.Color.Red;
        }

        private void btStaffbereichClose_Click(object sender, EventArgs e)
        {
            staffbereich = false;
            btStaffbereichFrei.Visible = true;
            btStaffbereichClose.Visible = false;
            lbStaffbereich.BackColor = System.Drawing.Color.Red;
        }

        private void btAktivitätenClose_Click(object sender, EventArgs e)
        {
            aktivitäten = false;
            btAktivitätenFrei.Visible = true;
            btAktivitätenClose.Visible = false;
            lbAktivitäten.BackColor = System.Drawing.Color.Red;
        }

        private void btReportsClose_Click(object sender, EventArgs e)
        {
            reports = false;
            btReportsFrei.Visible = true;
            btReportsClose.Visible = false;
            lbReports.BackColor = System.Drawing.Color.Red;
        }

        private void btKursverwaltungClose_Click(object sender, EventArgs e)
        {
            kursverwaltung = false;
            btKursverwaltungFrei.Visible = true;
            btKursverwaltungClose.Visible = false;
            lbKursverwaltung.BackColor = System.Drawing.Color.Red;
        }

        private void btFinanzenClose_Click(object sender, EventArgs e)
        {
            finanzen = false;
            btFinanzenFrei.Visible = true;
            btFinanzenClose.Visible = false;
            lbFinanzen.BackColor = System.Drawing.Color.Red;
        }

        private void btKundenClose_Click(object sender, EventArgs e)
        {
            kunden = false;
            btKundenFrei.Visible = true;
            btKundenClose.Visible = false;
            lbKunden.BackColor = System.Drawing.Color.Red;
        }

        private void btEinkleidungClose_Click(object sender, EventArgs e)
        {
            einkleidung = false;
            btEinkleidungFrei.Visible = true;
            btEinkleidungClose.Visible = false;
            lbEinkleidung.BackColor = System.Drawing.Color.Red;
        }

        private void btAdd_Click(object sender, EventArgs e)
        {
            //In die Tabelle ModulKeyMain schreiben
            // Generate new Object for DB
            ModulKey_Main newModulKey = new ModulKey_Main();
            newModulKey.ID = modulkey;
            newModulKey.Date = date;
            newModulKey.InUse = 0;
            newModulKey.Status = status;
            // Add to DB
            diveDatabase.AddToModulKey_Main(newModulKey);
            diveDatabase.SaveChanges();

            //In die Tabelle ModulKeyModule schreiben
            // Generate new Object for DB
            ModulKeyModule newModul1 = new ModulKeyModule();
            newModul1.ID = System.Guid.NewGuid();
            newModul1.ModulKeyMain = modulkey;
            newModul1.Modul = "Einstellungen";
            newModul1.Status = einstellungen.ToString();
            // Add to DB
            diveDatabase.AddToModulKeyModule(newModul1);
            diveDatabase.SaveChanges();

            //In die Tabelle ModulKeyModule schreiben
            // Generate new Object for DB
            ModulKeyModule newModul2 = new ModulKeyModule();
            newModul2.ID = System.Guid.NewGuid();
            newModul2.ModulKeyMain = modulkey;
            newModul2.Modul = "Verkauf";
            newModul2.Status = verkauf.ToString();
            // Add to DB
            diveDatabase.AddToModulKeyModule(newModul2);
            diveDatabase.SaveChanges();

            //In die Tabelle ModulKeyModule schreiben
            // Generate new Object for DB
            ModulKeyModule newModul3 = new ModulKeyModule();
            newModul3.ID = System.Guid.NewGuid();
            newModul3.ModulKeyMain = modulkey;
            newModul3.Modul = "Warenwirtschaft";
            newModul3.Status = warenwirtschaft.ToString();
            // Add to DB
            diveDatabase.AddToModulKeyModule(newModul3);
            diveDatabase.SaveChanges();

            //In die Tabelle ModulKeyModule schreiben
            // Generate new Object for DB
            ModulKeyModule newModul4 = new ModulKeyModule();
            newModul4.ID = System.Guid.NewGuid();
            newModul4.ModulKeyMain = modulkey;
            newModul4.Modul = "Verleih";
            newModul4.Status = verleih.ToString();
            // Add to DB
            diveDatabase.AddToModulKeyModule(newModul4);
            diveDatabase.SaveChanges();

            //In die Tabelle ModulKeyModule schreiben
            // Generate new Object for DB
            ModulKeyModule newModul5 = new ModulKeyModule();
            newModul5.ID = System.Guid.NewGuid();
            newModul5.ModulKeyMain = modulkey;
            newModul5.Modul = "Staffbereich";
            newModul5.Status = staffbereich.ToString();
            // Add to DB
            diveDatabase.AddToModulKeyModule(newModul5);
            diveDatabase.SaveChanges();

            //In die Tabelle ModulKeyModule schreiben
            // Generate new Object for DB
            ModulKeyModule newModul6 = new ModulKeyModule();
            newModul6.ID = System.Guid.NewGuid();
            newModul6.ModulKeyMain = modulkey;
            newModul6.Modul = "Aktivitäten";
            newModul6.Status = aktivitäten.ToString();
            // Add to DB
            diveDatabase.AddToModulKeyModule(newModul6);
            diveDatabase.SaveChanges();

            //In die Tabelle ModulKeyModule schreiben
            // Generate new Object for DB
            ModulKeyModule newModul7 = new ModulKeyModule();
            newModul7.ID = System.Guid.NewGuid();
            newModul7.ModulKeyMain = modulkey;
            newModul7.Modul = "Reports";
            newModul7.Status = reports.ToString();
            // Add to DB
            diveDatabase.AddToModulKeyModule(newModul7);
            diveDatabase.SaveChanges();

            //In die Tabelle ModulKeyModule schreiben
            // Generate new Object for DB
            ModulKeyModule newModul8 = new ModulKeyModule();
            newModul8.ID = System.Guid.NewGuid();
            newModul8.ModulKeyMain = modulkey;
            newModul8.Modul = "Kursverwaltung";
            newModul8.Status = kursverwaltung.ToString();
            // Add to DB
            diveDatabase.AddToModulKeyModule(newModul8);
            diveDatabase.SaveChanges();

            //In die Tabelle ModulKeyModule schreiben
            // Generate new Object for DB
            ModulKeyModule newModul9 = new ModulKeyModule();
            newModul9.ID = System.Guid.NewGuid();
            newModul9.ModulKeyMain = modulkey;
            newModul9.Modul = "Finanzen";
            newModul9.Status = finanzen.ToString();
            // Add to DB
            diveDatabase.AddToModulKeyModule(newModul9);
            diveDatabase.SaveChanges();

            //In die Tabelle ModulKeyModule schreiben
            // Generate new Object for DB
            ModulKeyModule newModul10 = new ModulKeyModule();
            newModul10.ID = System.Guid.NewGuid();
            newModul10.ModulKeyMain = modulkey;
            newModul10.Modul = "Kunden";
            newModul10.Status = kunden.ToString();
            // Add to DB
            diveDatabase.AddToModulKeyModule(newModul10);
            diveDatabase.SaveChanges();

            //In die Tabelle ModulKeyModule schreiben
            // Generate new Object for DB
            ModulKeyModule newModul11 = new ModulKeyModule();
            newModul11.ID = System.Guid.NewGuid();
            newModul11.ModulKeyMain = modulkey;
            newModul11.Modul = "Einkleidung";
            newModul11.Status = einkleidung.ToString();
            // Add to DB
            diveDatabase.AddToModulKeyModule(newModul11);
            diveDatabase.SaveChanges();

            MessageBox.Show("Schlüssel angelegt!");

            groupBox2.Enabled = false;
            groupBox3.Enabled = false;
            txShowKey.Text = "";
        }

        private void btClose_Click(object sender, EventArgs e)
        {
            btFree.Visible = true;
            btClose.Visible = false;
            status = "close";
            label13.BackColor = System.Drawing.Color.Red;
        }

        private void btFree_Click(object sender, EventArgs e)
        {
            btFree.Visible = false;
            btClose.Visible = true;
            status = "frei";
            label13.BackColor = System.Drawing.Color.Green;
        }

        private void ModulKeyAdd_Load(object sender, EventArgs e)
        {
            groupBox2.Enabled = false;
            groupBox3.Enabled = false;
        }
    }
}
